package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 咕唧
 * @Date 2022/5/20 15:33
 * @Version 1.0
 */
@Controller
@RequestMapping("/test")
public class UserController {

    /**
     * 转发
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @RequestMapping("/add1")
    public void addUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("UserController的addUser方法执行了");
        request.getRequestDispatcher("/add2").forward(request, response);
    }

    @RequestMapping("/add2")
    public void addUser2(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser2222方法执行了");
    }

    /**
     * 相对地址
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/add3")
    public String addUser3(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser3333方法执行了");
        return "forward:add2";
    }

    /**
     * 绝对地址
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/add4")
    public String addUser4(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser4444方法执行了");
        return "forward:/test/add2";
    }

    @RequestMapping("/add5")
    public String addUser5(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser55555方法执行了");
        return "/test/add2";
    }

    @RequestMapping("/add6")
    public String addUser6(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser6666方法执行了");
        return "add2";
    }

    /**
     * 重定向
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/add7")
    public String addUser7(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser7777方法执行了");
        return "redirect:add2";
    }

    @RequestMapping("/add8")
    public String addUser8(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("UserController的addUser8888方法执行了");
        return "redirect:test/add2";
    }

}
